package cn.afactory.tygz.ui.base.utils.sns;

import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.Display;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;

import cn.afactory.tygz.R;


/**
 * Created by loza on 2015/6/14.
 */
public class ViewTools {

    /**
     * 设置点赞动画
     * @param tv
     */
    public static void setPraiseAni(TextView tv){
//        ScaleAnimation scale_praise = PraiseAnimation.getShowSacleAnimation();
//        scale_praise.setAnimationListener(HealthSquareDetailActivity.getAnimationListener(tv));
//        tv.setClickable(false);
//        tv.startAnimation(scale_praise);
    }

    /**
     * 是否点赞，设置VIEW
     * @param tv
     * @param IsPraised
     */
    public static void setPraiseView(TextView tv, Boolean IsPraised, int praiseNum){
        if (praiseNum > 0) {
            tv.setText(String.valueOf(praiseNum));
            tv.setGravity(Gravity.LEFT|Gravity.CENTER);
        } else {
            tv.setText("赞");
            tv.setGravity(Gravity.LEFT|Gravity.CENTER);
        }

        if(!IsPraised){
            setTextLeftIcon(tv, R.drawable.ic_unprasize);
        } else {
            setTextLeftIcon(tv, R.drawable.ic_prasized);
        }
    }

    /** 设置左侧图片
     * @param tv
     * @param id
     */
    public static void setTextLeftIcon(TextView tv, int id) {
        if (id == 0) {
            tv.setCompoundDrawables(null, null, null, null);
            return;
        }
        Drawable drawable = tv.getContext().getResources().getDrawable(id);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv.setCompoundDrawables(drawable, null, null, null);
        tv.setGravity(Gravity.LEFT | Gravity.CENTER);
    }

    /** 设置左侧图片
     * @param tv
     * @param id
     */
    public static void setTextRightIcon(TextView tv, int id) {
        if (id == 0) {
            tv.setCompoundDrawables(null, null, null, null);
            return;
        }
        Drawable drawable = tv.getContext().getResources().getDrawable(id);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv.setCompoundDrawables(null, null, drawable, null);
//        tv.setGravity(Gravity.LEFT | Gravity.CENTER);
    }
    /**
     * 获取当前屏幕宽度
     * @param ctx
     * @return
     */
    public static int getScreenWidth(Context ctx) {
        if (null == ctx) {
            return 0;
        }
        WindowManager windowManager = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        if (Build.VERSION.SDK_INT < 13) {
            return display.getWidth();
        }
        Point point = new Point();
        display.getSize(point);
        return point.x;
    }

}
